<?php

namespace App\Services\Game\Other\Activity;

use App\Services\Service;
use App\Models\Game\Config\Activity;

class RankingService extends Service
{

    /**
     * 获取配置
     *
     * @param string $platCode
     * @return Activity
     */
    public function getConfig($platCode): ?Activity
    {
        return Activity::findByType($platCode, Activity::TYPE_RANKING);
    }

    /**
     * 更新配置
     *
     * @param string $platCode
     * @param \Illuminate\Http\Request $request
     * @return Activity
     */
    public function update($platCode, $request): Activity
    {
        $data = $request->only(['enable', 'expire_time', 'info']);

        // 创建或修改活动配置
        $activity = Activity::updateOrCreateByType($platCode, Activity::TYPE_RANKING, $data);

        // 通知游戏端配置修改
        $activity->syncGameService();

        return $activity;
    }
}
